import { request } from '@umijs/max';

/** 分页查询所有角色 GET /system/role/list */
export async function getRoleList(params?: API.QueryRolePageParams) {
  return request<API.QueryPageResp<API.Role>>('/system/role/list', {
    method: 'GET',
    params,
  });
}

/** 新增角色 POST /system/role/add */
export async function addRole(params: API.Role) {
  return request<API.Resp>('/system/role/add', {
    method: 'POST',
    data: params,
  });
}

/** 修改角色 POST /system/role/update */
export async function updateRole(params: API.Role) {
  return request<API.Resp>('/system/role/update', {
    method: 'POST',
    data: params,
  });
}

/** 获取单个角色 GET /system/role/get/{id} */
export async function getRoleById(id: React.Key) {
  return request<API.Resp<API.Role>>(`/system/role/get/${id}`, {
    method: 'GET',
  });
}

/** 删除角色 POST /system/role/delete */
export async function deleteRoleById(id: React.Key) {
  return request<API.Resp>(`/system/role/delete`, {
    method: 'POST',
    params: {
      id,
    },
  });
}

/** 新增角色和菜单关联关系 POST /system/role/addRoleMenu */
export async function addRoleMenu(params: API.AddRoleMenuParams) {
  return request<API.Resp>('/system/role/addRoleMenu', {
    method: 'POST',
    data: params,
  });
}

/** 查询角色和菜单关联关系 GET /system/role/listRoleMenus/{roleId} */
export async function listRoleMenus(roleId: React.Key) {
  return request<API.Resp<number[]>>(`/system/role/listRoleMenus/${roleId}`, {
    method: 'GET',
  });
}

/** 赋予角色数据权限 POST /system/role/addRoleData */
export async function addRoleData(params: API.AddRoleDataParams) {
  return request<API.Resp>('/system/role/addRoleData', {
    method: 'POST',
    data: params,
  });
}

/** 查询角色和菜单关联关系 GET /system/role/select/list */
export async function getRoleSelectList() {
  return request<API.Resp<API.Role[]>>(`/system/role/select/list`, {
    method: 'GET',
  });
}
